package com.api.shopapi.mapper;

import com.api.shopapi.entity.MeshDevice;
import com.api.shopapi.entity.dto.MeshDeviceDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
@Mapper
public interface MeshDeviceMapper {

    @Insert("insert into mesh_device (DeviceCode,HeaderCode,DeviceId,DeviceName,DeviceType,Brand,Model,Zone,AddTime) values " +
            "(#{meshDevice.DeviceCode},#{meshDevice.HeaderCode},#{meshDevice.DeviceId},#{meshDevice.DeviceName}," +
            "#{meshDevice.DeviceType},#{meshDevice.Brand},#{meshDevice.Model},#{meshDevice.Zone},#{meshDevice.AddTime})")
    int insert(@Param("meshDevice") MeshDevice meshDevice);




    @Select("<script>" +
            "select * from mesh_device md left join yj_header yj on md.HeaderCode = yj.HeaderCode where " +
            "yj.GwId=#{gwId} " +
            "and yj.Name = 'MeshDevPush' " +
            " <if test ='deviceName !=null and deviceName!=\"\"  '>" +
            "  and md.Model = #{model}  " +
            " </if>" +
            "order by md.AddTime desc" +
            "</script> ")
    List<MeshDeviceDTO> getPageByGwId(@Param("gwId") String gwId,@Param("deviceName") String model);
}
